home *** CD-ROM | disk | FTP | other *** search
/ Internet.Works 41 / Issue 41.iso / pc / PCSoftware / Netscape 6 Official Release / nim.xpi / bin / chrome / aim.jar / content / aim / msgHdrViewAddresses.js < prev    next >
Encoding:
JavaScript  |  2000-09-13  |  6.4 KB  |  198 lines

  1. /////////////////////////////////////////////////////////////////////
  2. // These are our hooks into the public mozilla
  3. // header viewing code. This is where we can insert AIM presence 
  4. // information into the message pane.
  5. //////////////////////////////////////////////////////////////////////
  6.  
  7. var gPrefs = Components.classes["@mozilla.org/preferences;1"];
  8. gPrefs = gPrefs.getService();
  9. gPrefs = gPrefs.QueryInterface(Components.interfaces.nsIPref);
  10.  
  11. // list of emails we did not have a buddy list association with
  12. var emailList = new Array();
  13. var emailNodeList = new Array();
  14. var emailNodeList2 = new Array();
  15.  
  16. // callback for RequestGroupPresenceByEmailAddress()
  17. var LocateCallback = new Object();
  18.  
  19. LocateCallback.OnRequestGroupInfoPresenceComplete = function(pArraySize, pEmailList, pScreenNameList, pPresenceList)
  20. {
  21.   for(i in emailNodeList)
  22.   {
  23.     var emailNode = emailNodeList[i];
  24.     // always set the screen name...even if the user is not online...
  25.     if (pScreenNameList[i])
  26.     {
  27.       emailNode.setTextAttribute("IMScreenName", pScreenNameList[i]);
  28.       if (emailNodeList2[i])
  29.         emailNodeList2[i].setTextAttribute("IMScreenName", pScreenNameList[i]);
  30.     }
  31.  
  32.     if(pPresenceList[i])
  33.     {
  34.       emailNode.setAttribute("BuddyStateString", "ActiveOnline");
  35.  
  36.       // this silly align hack is because css isn't noticing the alignment
  37.       // attribute unless I set it to something...then set it back to what
  38.       // I really want...
  39.       emailNode.setAttribute("align", "left");
  40.       emailNode.setAttribute("align", "right");
  41.       emailNode.setAttribute("max-height", "15px");
  42.  
  43.       if(emailNodeList2[i])
  44.       {
  45.         emailNode = emailNodeList2[i];
  46.         emailNode.setAttribute("BuddyStateString", "ActiveOnline");
  47.  
  48.         // this silly align hack is because css isn't noticing the alignment
  49.         // attribute unless I set it to something...then set it back to what
  50.         // I really want...
  51.         emailNode.setAttribute("align", "left");
  52.         emailNode.setAttribute("align", "right");
  53.         emailNode.setAttribute("max-height", "15px");
  54.       }
  55.     }
  56.   }
  57.   emailList.length = 0;
  58.   emailNodeList.length = 0;
  59.   emailNodeList2.length = 0;
  60. }
  61.  
  62. LocateCallback.OnRequestGroupInfoPresenceError = function(pErrMsg) 
  63. {
  64.     //dump("LocateCallback.OnRequestGroupInfoPresenceError\n");
  65.   emailList.length = 0;
  66.   emailNodeList.length = 0;
  67.   emailNodeList2.length = 0;
  68. }
  69.  
  70. /* AddExtraAddressProcessing is called by the msgHdrViewOverlay whenever it encounters
  71.    an email address. This gives us the chance to insert presence information.
  72.    
  73.    It's important to realize that each email address is represented by a borderless
  74.    title button. For presence, we just need to poke the image url associated
  75.    with that title button
  76. */
  77.  
  78. function AddExtraAddressProcessing(emailAddress, emailNode)
  79. {
  80.   // take the email Address, figure out if we have an AIM uri for this
  81.   // email address...if we do, create a titled button element and based on
  82.   // the online presence, give that button a class. Add it to our watch list
  83.   // so we can change this dom element later on. And then insert it into the enclosingNode
  84.  
  85.  
  86.   if (emailAddress && aimABInfo && aimBuddyInfo)
  87.   {
  88.     if(gPrefs)
  89.     {
  90.       var showPresence = gPrefs.GetBoolPref("aim.mail.presence");
  91.       if(!showPresence)
  92.         return;
  93.     }
  94.     else
  95.       return;
  96.  
  97.     try 
  98.     {
  99.       var screenName = aimABInfo.GetScreenNameFromEmail(emailAddress);
  100.     }
  101.     catch (ex)
  102.       {}
  103.     if (screenName)
  104.     {
  105.        var rdfResourceForName = aimBuddyInfo.GetUserResource(screenName);
  106.        if (rdfResourceForName)
  107.        {
  108.           var target = AimDataSource.GetTarget(rdfResourceForName, buddyStateString, true);
  109.           if (target)
  110.             SetPresence(emailNode, target);
  111.           domNodes[rdfResourceForName.Value] = emailNode;
  112.        }
  113.  
  114.        // be sure to set the screen name as an attribute on the node so we can get it later...
  115.        emailNode.setTextAttribute("IMScreenName", screenName);
  116.     }
  117.     else
  118.     {
  119.       // add this email address to the list that will be processed later with the LocateManager
  120.  
  121.       var length = emailList.length;
  122.       if(emailList[length-1] == emailAddress && length != 0)
  123.       {
  124.         emailNodeList2[length-1] = emailNode;
  125.       }
  126.       else
  127.       {
  128.         emailList[length] = emailAddress;
  129.         emailNodeList[length] = emailNode;
  130.       }
  131.     }
  132.   }
  133. }
  134.  
  135. // This will kick off the group processing of presence for email addresses
  136. function FinishEmailProcessing()
  137. {
  138.   //dump("FinishEmailProcessing()\n");
  139.  
  140.   if(gPrefs)
  141.   {
  142.     var showPresence = gPrefs.GetBoolPref("aim.mail.presence");
  143.     if(!showPresence)
  144.       return;
  145.   }
  146.   else
  147.     return; 
  148.  
  149.   try
  150.   { aimLocateManager.RequestGroupPresenceByEmailAddress(LocateCallback, emailList.length, emailList); }
  151.   catch(ex)
  152.   {  
  153.     emailList.length = 0;
  154.     emailNodeList.length = 0;
  155.     emailNodeList2.length = 0;
  156.   }
  157. }
  158.  
  159. // NotifyClearAddresses --> use to clear any observers on the email
  160. // addresses that maybe in the hdr view overlay. Each time a new
  161. // message is loaded in message pane, we'll call this function...
  162. function NotifyClearAddresses()
  163. {
  164.   domNodes = new Object(); // throw away our knowledge of old data sources..
  165.  
  166.   //emailList = new Array();
  167.   //emailNodeList = new Array();
  168.   //LocateCallback = new Object();
  169. }
  170.  
  171. // fillEmailAddressMenu - the oncreate handler for the email address popu menu.
  172. // node --> the popup node that has been selected.
  173. function fillEmailAddressMenu(node)
  174. {
  175.   // we need to determine if we are online or not. If we aren't online, disable the
  176.   // AIM related menu items. If we are online, then make sure they are enabled.
  177.   var target = AimDataSource.GetTarget(AimSession, SessionState, true);
  178.   var state = target.QueryInterface(Components.interfaces.nsIRDFLiteral).Value;
  179.   var online = false;
  180.   if (state == "Online" || "OnlineAway" == state)
  181.     online = true;
  182.  
  183.   var screenName = node.getAttribute("IMScreenName");
  184.   var haveScreenName = false;
  185.   if (screenName && screenName != "")
  186.     haveScreenName = true;
  187.  
  188.   ShowMenuItem("aimEmailAddressSeparator", online);
  189.  
  190.   ShowMenuItem("sendIMForAddress", online);
  191.     EnableMenuItem("sendIMForAddress", online && haveScreenName);
  192.  
  193.   ShowMenuItem("addAddressToBuddyList", online);
  194.     EnableMenuItem("addAddressToBuddyList", online && haveScreenName);
  195.   
  196.   return true;
  197. }
  198.